package  
{
	import net.flashpunk.World;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.Sfx;
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class SecondScene extends World
	{
		/*[Embed(source = "sfx/Then He Kissed Me - The Crystals.mp3")]private const SFX:Class;
		private var music:Sfx;*/
		
		[Embed(source = "img/copacabana.png")]	private const IMG_BACK:Class;
		private var imgBack:Image;
		
		private var player:Player;
		private var carGuy:CarGuy
		private var girl:Girl;
		private var line:Vector.<LineGuy>;
		private var texto:Boolean = false;
		
		private var music:Music = new Music();
		
		public function SecondScene() 
		{
			imgBack = new Image(IMG_BACK);
			imgBack.x = 0;
			imgBack.y = 0;
			addGraphic(imgBack);
			
			//music = new Sfx(SFX) ;
			if(!music.isPlaying())
				music.play();
			
			player = new Player(100, 400);
			girl = new Girl(30, 400);
			carGuy = new CarGuy(300, 400);
			add(carGuy);
			
			line = new Vector.<LineGuy>;
			
			var aux:LineGuy;
			
			aux = new LineGuy(550, 300);
			line.push(aux);
			add(aux);
			aux = new LineGuy(600, 350);
			line.push(aux);
			add(aux);
			aux = new LineGuy(500, 400);
			line.push(aux);
			add(aux);
			
			add(girl);
			add(player);
			
			aux = new LineGuy(600, 500);
			line.push(aux);
			add(aux);
			aux = new LineGuy(500, 550);
			line.push(aux);
			add(aux);
			
			
			
			
		}
		
		
		override public function update():void
		{
			
			if (player.state == "hand")
			{
				girl.stop();
			}
			else
				girl.walk();
			
			if (player.collide("CarGuy", player.x-10, player.y) && carGuy.state!="walking")
			{
				FP.world = new SecondScene();
				removeAll();
			}
			
			if ((carGuy.x - player.x) < 60)
			{
				if (player.state == "hand" && carGuy.state == "hand")
				{
					if(!texto)
					{
						add(new Dialog("Aqui tiene las llaves", player.x-200, player.y, 2, player.y - 50));
						texto = true;
					}
					carGuy.caminar();
					player.handWalking = true;
					
				}
			}
			
			for each(var g:LineGuy in line)
			{
				if (g.collide("Player", g.x, g.y))
				{
					if(player.state=="handwalking")
					{
						g.x += 1;
						if(player.y>g.y)g.y -= 2;
						else g.y += 1;
					}
					else
					{
						player.x -= 1; 
						girl.x -= 1;
					}
				}	
			}
			
			
			if (girl.x > FP.screen.width)
			{
				FP.world = new ThirdScene();
				removeAll();
			}
			
			super.update();
		}
	}

}